<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>1</title>
</head>

<body onload="init()">
		<canvas id="mycanvas" width="400" height="100" style="border: 1px solid #888888;"></canvas>
</body>

<script type="text/javascript">

//定义数组图片集合
			var marios = new Array("img/1.png", "img/2.png", "img/3.png");
			var mario = new Image();
			var canvas;
			var ctx;
			var i = -1;
			var num = 0;
 
			function init() {
				//alert("----------")
				setInterval("draw()", 200);
			}
 
			function draw() {
				i++;
				// alert(i)
				mario.src = marios[i];
				// alert(mario)
				canvas = document.getElementById("mycanvas");
				ctx = canvas.getContext("2d");
				ctx.clearRect(0, 0, 400, 100) 
				ctx.drawImage(mario, num, 0);
				num += 10;
				if (num == 400) {
					num = 0;
				}
				if (i == 2) {
					i = -1;
				}
			}
</script>
	

</html>